#ifndef QXGAME_FONT_H
#define QXGAME_FONT_H

#include <string>
#include "SDL.h"
#include "SDL_ttf.h"

class GameFont {
public:
    GameFont() = default;

    ~GameFont()
    {
        SDL_DestroyTexture(texText);
        texText = nullptr;
    }

    void OnRender(SDL_Renderer *renderer, TTF_Font *font, SDL_Point point,
                  const SDL_Color &color, const std::string &content)
    {
        SDL_DestroyTexture(texText);
        texText = nullptr;
        sufText = TTF_RenderUTF8_Blended(font, content.data(), color);
        texText = SDL_CreateTextureFromSurface(renderer, sufText);

        SDL_Rect rect = {point.x - sufText->w / 2, point.y - sufText->h / 2, sufText->w, sufText->h};
        SDL_RenderCopy(renderer, texText, nullptr, &rect);

        SDL_FreeSurface(sufText);
    }

private:
    SDL_Surface *sufText = nullptr;
    SDL_Texture *texText = nullptr;
};


#endif //QXGAME_FONT_H
